package com.freecat.xmqgct.mvp.ui.activity;

import android.content.DialogInterface;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;

import com.blankj.utilcode.util.ToastUtils;
import com.freecat.xmqgct.R;
import com.freecat.xmqgct.app.MyApp;
import com.freecat.xmqgct.mvp.model.entity.Project;
import com.freecat.xmqgct.mvp.presenter.MainPresenter;
import com.freecat.xmqgct.mvp.ui.adapter.ProjectAdapter;

import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import io.objectbox.Box;
import me.jessyan.art.mvp.IView;
import me.jessyan.art.mvp.Message;

public class SearchActivity extends BaseActivity<MainPresenter> implements IView {

    /*
    * 搜索列表页
    * 该页面显示项目搜索结果
    * */

    private Box<Project> ProjectBeanBox;

    List<Project> projectList;

    ProjectAdapter projectAdaptesr;

    @BindView(R.id.lv_search_project_list)
    ListView lv_search_project_list;

    @BindView(R.id.iv_back)
    ImageView iv_back;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }



    @Override
    public int initView(@Nullable Bundle savedInstanceState) {
        return R.layout.activity_search;
    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        ProjectBeanBox = MyApp.getBoxStore().boxFor(Project.class);
        projectList=ProjectBeanBox.query().build().find();
        if (null != projectList && projectList.size() > 0) {
            projectAdaptesr = new ProjectAdapter(mContext,projectList,iBack,false);
            lv_search_project_list.setAdapter(projectAdaptesr);
            lv_search_project_list.setVisibility(View.VISIBLE);
//            llEmpty.setVisibility(View.GONE);
        } else {
            lv_search_project_list.setVisibility(View.GONE);
//            llEmpty.setVisibility(View.VISIBLE);
        }

    }

    @Nullable
    @Override
    public MainPresenter obtainPresenter() {
        return null;
    }

    @Override
    public void showMessage(@NonNull String message) {

    }

    @Override
    public void handleMessage(@NonNull Message message) {

    }

    @OnClick({R.id.iv_back, R.id.iv_add})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_back:

                finish();
                break;
        }
    }

    IBack iBack = new IBack() {
        @Override
        public void Click(int position) {



        }


        @Override
        public void del(int position) {

            new AlertDialog.Builder(mContext).setMessage("确定要删除吗？")
                    .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {

                        }
                    }).setNegativeButton("取消", null)
                    .show();

        }

        @Override
        public void edit(int position) {

        }
    };

}